package com.example.yd202xslzy;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.yd202xslzy.beans.Lianxi;
import com.example.yd202xslzy.retrofitservice.RetrofitService;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class MainActivity extends AppCompatActivity {
    Button button;//注册
    Button button2;//登录

    EditText editText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        button = findViewById(R.id.button);//注册

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                final Intent intent =new Intent(MainActivity.this,RegisterActivity.class);
                startActivity(intent);
                finish();
            }
        });

        editText = findViewById(R.id.editText2);

        button2 = findViewById(R.id.button2);//登录

        button2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                final Intent intent1 = new Intent(MainActivity.this, HoneActivity.class);
                intent1.putExtra("user",editText.getText().toString());
                startActivity(intent1);
                finish();

                Retrofit retrofit = new Retrofit.Builder()
                        .baseUrl("http://172.24.10.175:8080/")
                        .addConverterFactory(GsonConverterFactory.create())
                        .build();

                RetrofitService retrofitService = retrofit.create(RetrofitService.class);

                Call<Lianxi> dishCall = retrofitService.getLianxi("lnn","123456");

                dishCall.enqueue(new Callback<Lianxi>() {
                    @Override
                    public void onResponse(Call<Lianxi> call, Response<Lianxi> response) {
                        Lianxi lianxi = response.body();
                        System.out.println("asd:");
                        Toast.makeText(MainActivity.this, "ID --> "+lianxi.getUserid(), Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onFailure(Call<Lianxi> call, Throwable t) {

                    }

                });
            }
        });
    }

}
